package com.iap.common.service
{
	import com.iap.client.event.FillerEvent;
	import com.iap.app.data.AppData;
	import com.iap.app.data.IAppData;
	import com.iap.app.model.ServiceResponse;
	import com.iap.common.model.Filler;
	import com.iap.common.translator.FillerTranslator;
	
	import org.robotlegs.mvcs.Actor;
	
	public class FillerService extends Actor implements IFillerService
	{
		[Inject]
		public var data:IAppData;
		
		private var _task:String;
		public function set task(value:String):void { _task = value; }
		
		public function getList():void
		{
			data.dataComplete.add(responseHandler);
			data.load(this, AppData.JOB_GET);
		}
		
		public function save(model:Filler):void
		{
			data.dataComplete.add(responseHandler);
			data.load(this, AppData.JOB_SAVE, model);
		}
		
		public function remove(model:Filler):void
		{
			data.dataComplete.add(responseHandler);
			data.load(this, AppData.JOB_REMOVE, model);
		}
		
		private function responseHandler(response:ServiceResponse):void
		{
			data.dataComplete.remove(responseHandler);
			response.task = _task;
			response.result = FillerTranslator.translate(response.rawdata);
			dispatch(new FillerEvent(FillerEvent.RESPONSE, response));
		}
	}
}